home *** CD-ROM | disk | FTP | other *** search
RISC OS BBC BASIC V Source | 1994-09-20 | 11.4 KB | 361 lines |
- >!RunImage
- Program Test Program For ImpulseII
- DefineConstants
- InitApp
- Impulse_Init("<ImpDemo$Dir>.")
- Impulse_DefineMethods
- quit%:
- start of poll loop
- "Wimp_Poll", 1, bk%
- reason%
- "Impulse_Decode", reason%, bk%, , , , IMPULSE_METHOD_TABLE, TASK_ID%
- reason%, , , , , token,params,object
- reason%
- !
- "Wimp_OpenWindow",,bk%
- "
- "Wimp_CloseWindow",,bk%
- button
- menuselect
- 17,18:
- message
- IMPULSE_COMMAND,IMPULSE_REQUEST:
- )
- command( token, params, object )
- "Wimp_CloseDown"
- command(token,params,object)
- token
- G_Token_OpenWin% :
- !bk% = mainw%
- 1)
- "Wimp_GetWindowState", , bk%
- bk%!28 = -1
- 3%
- "Wimp_OpenWindow", , bk%
- G_Token_CloseWin% :
- !bk% = mainw%
- 8&
- "Wimp_CloseWindow", , bk%
- G_Token_S1_On% :
- <(
- shell_IconSelect( mainw%, 9 )
- G_Token_S2_On% :
- @)
- shell_IconSelect( mainw%, 10 )
- G_Token_S1_Off% :
- D*
- shell_IconDeselect( mainw%, 9 )
- G_Token_S2_Off% :
- H+
- shell_IconDeselect( mainw%, 10 )
- Update_MainWindow( token, params, object )
- Update_MainWindow( token, params, object )
- shell_IconPutData( mainw%, 3,
- ( token ),
- shell_IconPutData( mainw%, 1, $params,
- shell_IconPutData( mainw%, 5, $object,
- shell_IconPutData( mainw%, 7, "&" +
- ~reason%,
- button
- bk%!8
- Read button state
- bk%!12 = -2
- e4
- If Menu pressed over iconbar, create menu
- f6
- "Wimp_CreateMenu", , menu%, !bk% - 64, 184
- bk%!12
-
- n,
- <SELECT> used on iconbar icon..
- !bk% = mainw%
- p*
- "Wimp_GetWindowState", , bk%
- bk%!28 = -1
- r&
- "Wimp_OpenWindow", , bk%
- menuselect
- button%
- "Wimp_GetPointerInfo", , bk% + 256
- read button state
- button% = bk%!264
- !bk%
- quit if item 1 chosen
- quit% =
- re-open menu if Adjust was pressed
- button% = 1
- "Wimp_CreateMenu", , menu%
- message
- bk%!16
- )
- quit%=
- string(a%)
- convert a null-terminated string into CR-terminated
- ?a%<>0
- a$+=
- ?a%:a%+=1
- InitApp
- bk% 2000,menu% 75,ind% 3000,name% 11
- quit% = 0
- TASK_NAME$ = "ImpDemo"
- err% = 0
- "OS_ReadVarVal", TASK_NAME$ + "$Dir",bk%,255,0,3
- ,,i%
- bk%?i%=13:dir$=$bk%
- "Wimp_Initialise", 200, &4B534154, TASK_NAME$
- , ,TASK_ID%
- error:
- "Wimp_OpenTemplate", , dir$ + ".Templates"
- i% = ind%
- 'infohan% =
- CreateWindow("InfoBox")
- %mainw% =
- CreateWindow("mainw")
- "Wimp_CloseTemplate"
- %!bk%=-1:bk%!4=0:bk%!8=0:bk%!12=68
- /bk%!16=68:bk%!20=&3002:$(bk%+24)="!ImpDemo"
- "Wimp_CreateIcon",,bk%
- setupmenu(menu%)
- +buff% =
- _heap_get(256):
- text buffer..
- DefineConstants
- setupmenu(m%)
- $m%,num%:len%=
- ($m%)-2
- !m%!12=&70207:m%!20=44:m%!24=0
- m%+=28:
- i%=1
- num%
- !m%=-&80*(i%=num%):
- m%!4
- # m%!8=&7009021:
- a$:$(m%+12)=a$
- a$>len% len%=
- m%+=24
- :menu%!16=16*(len%+1)
- CreateWindow(template_name$)
- window_handle%
- "Wimp_LoadTemplate", , bk%, i%, ind% + 3000, -1, template_name$, 0
- ,,i%
- "Wimp_CreateWindow", , bk%
- window_handle%
- = window_handle%
- error
- report(
- $ + " - internal error code "+
- "Wimp_CloseDown"
- report(error_message$, error_box_flags%)
- error_nr%
- error_nr% = 1
- !bk% = error_nr%
- &$(bk% + 4) = error_message$ +
- "Wimp_ReportError", bk%, error_box_flags%, TASK_NAME$
- Data for iconbar menu
- ImpDemo,2,infohan%,Info,-1,Quit
- Impulse_DefineMethods
- Impulse_MakeMethod( 0, G_Token_OpenWin% , "OpenWin" , "" )
- Impulse_MakeMethod( 0, G_Token_CloseWin%, "CloseWin", "" )
- Impulse_MakeMethod( 0, G_Token_S1_On%, "S1_On", "" )
- Impulse_MakeMethod( 0, G_Token_S2_On%, "S2_On", "" )
- Impulse_MakeMethod( 0, G_Token_S1_Off%, "S1_Off", "" )
- Impulse_MakeMethod( 0, G_Token_S2_Off%, "S2_Off", "" )
- shell_ImpulseWindupMethods
- -----------------------------------------------------------------------
- Memory Management Routines
- -----------------------------------------------------------------------
- _heap_get(size%)
- ptr%,heap%,flags%
- Returns pointer to new memory block unless claim fails
- in which case -1 is returned
- First find start address of RMA..
- "OS_ReadDynamicArea",1
- heap%
- Now claim memory, trapping errors by using X form of SWI..
- "XOS_Module",6,,,size%
- ,,ptr%;flags%
- If error occured return -1, else return address of allocated
- block
- (flags%
- ptr% = -1
- = ptr%
- _heap_release(
- ptr%)
- maxfree%,nrpages%,flags%
- Returns 0 if block released OK
- Returns -1 if operation failed (i.e. block doesn't exist)
- "XOS_Module",7,,ptr%
- ;flags%:
- Free the block
- (flags%
- 1) = 0
- Block was released successfully...
- ptr% = 0
- Error occured trying to free the block, return -1 to signal to the
- program that something went wrong (normally the program would ignore
- this anyway)
- ptr% = -1
- -----------------------------------------------------------------------
- Icon Handling Routines
- -----------------------------------------------------------------------
- shell_IconSelect(WindowHandle%,IconHandle%)
- shell_IconSetState(WindowHandle%,IconHandle%,&200000,&200000)
- shell_IconDeselect(WindowHandle%,IconHandle%)
- shell_IconSetState(WindowHandle%,IconHandle%,0,&200000)
- shell_IconSetState(WindowHandle%,IconHandle%,EorWord%,ClearWord%)
- icon_blk%
- M!icon_blk% =
- _heap_get( 16 )
- !icon_blk% = WindowHandle%
- icon_blk%!04 = IconHandle%
- icon_blk%!08 = EorWord%
- icon_blk%!12 = ClearWord%
- "Wimp_SetIconState", , icon_blk%
- _heap_release( icon_blk% )
- shell_IconGetData(whandle%,ihandle%)
- result$,icon_blk%
- icon_blk% =
- _heap_get(40)
- icon_blk%!0 = whandle%
- icon_blk%!4 = ihandle%
- "Wimp_GetIconState",,icon_blk%
- (icon_blk%!24
- (1<<8))<>0
- result$=$(icon_blk%!28)
- result$=$(icon_blk%+28)
- _heap_release(icon_blk%)
- =result$
- shell_IconPutData(whandle%,ihandle%,data$,redraw)
- blk%,old_str$
- j4old_str$ =
- shell_IconGetData(whandle%,ihandle%)
- data$ <> old_str$
- blk%=
- _heap_get(40)
- blk%!0 = whandle%
- blk%!4 = ihandle%
- "Wimp_GetIconState",,blk%
- (blk%!24
- (1<<8)) <> 0
- $(blk%!28) = data$
- y! $(blk% + 28) =
- data$,11)
- redraw <> 0
- blk%!8 = 0
- blk%!12 = 0
- $
- "Wimp_SetIconState",,blk%
- _heap_release(blk%)
- -----------------------------------------------------------------------
- ImpulseII Handling Routines
- -----------------------------------------------------------------------
- Impulse_Init(Root$)
- ( "RMEnsure Impulse 0.18 *RMLoad " + Root$ + "ImpulseII" )
- "Impulse_Initialise", 18, TASK_ID%, TASK_NAME$, -1
- IMPULSE_TABLE_SIZE = &400
- IMPULSE_METHOD_TABLE IMPULSE_TABLE_SIZE
- 6G_Impulse_NextMethod% = IMPULSE_METHOD_TABLE + 4
- IMPULSE_METHOD_TABLE!0 = 0
- G_Impulse_NextToken% = 1
- G_Impulse_TxTag% = 0
- G_Impulse_TxInProgress% =
- G_Impulse_TxTop% = 0
- G_Impulse_TxPtr% = 0
- Global Constants
- IMPULSE_COMMAND = &200
- IMPULSE_REQUEST = &201
- IMPULSE_REPLY = &202
- IMPULSE_SENDDATA = &203
- IMPULSE_RECEIVEDATA = &204
- Impulse_MakeMethod( Flags%,
- Token%, Method$, Syntax$ )
- .Token% = G_Impulse_NextToken%
- !G_Impulse_NextToken% += 1
- &G_Impulse_NextMethod%!0 = Flags%
- &G_Impulse_NextMethod%!4 = Token%
- !G_Impulse_NextMethod% += 8
- '$G_Impulse_NextMethod% = Method$
- (G_Impulse_NextMethod% +=
- Method$
- !G_Impulse_NextMethod%?0 = 0
- !G_Impulse_NextMethod% += 1
- '$G_Impulse_NextMethod% = Syntax$
- (G_Impulse_NextMethod% +=
- Syntax$
- !G_Impulse_NextMethod%?0 = 0
- !G_Impulse_NextMethod% += 1
- EG_Impulse_NextMethod% = ((G_Impulse_NextMethod% + 3)
- 4) * 4
- shell_ImpulseWindupMethods
- G_Impulse_NextMethod%!0 = -1
- G_Impulse_NextMethod%!4 = -1
- G_Impulse_NextMethod%?8 = 0
- G_Impulse_NextMethod%?9 = 0
- G_Impulse_NextMethod% += 10
- G_Impulse_NextMethod% > IMPULSE_METHOD_TABLE + IMPULSE_TABLE_SIZE
- 200,"Impulse has run out of room in making methods" )
- shell_ImpulseSendCommand( Command$ )
- "Impulse_SendMessage", IMPULSE_COMMAND, Command$, 0, 0, 0, 0, TASK_ID%, 0
- shell_ImpulseSendRequest( Request$, Tag% )
- "Impulse_SendMessage", IMPULSE_REQUEST, Request$, 0, 0, 0, Tag%, TASK_ID%
- shell_ImpulseSendReply( Reply$, Tag% )
- Size%
- /Size% = G_Impulse_TxTop% - G_Impulse_TxPtr%
- "Impulse_SendMessage", IMPULSE_REPLY, Reply$, , , , Tag%, TASK_ID%, Size%
- shell_ImpulseSetupTransmission( Block%, Size% )
- G_Impulse_TxPtr% = Block%
- 7G_Impulse_TxTop% = (Block% + Size% + 4)
- &FFFFFFFC
- G_Impulse_TxInProgress% =
- shell_ImpulseTransmitData( Allowed% )
- Size%
- /Size% = G_Impulse_TxTop% - G_Impulse_TxPtr%
- (Size% < Allowed%)
- (Size% <= 0)
- " G_Impulse_TxInProgress% =
- Size% > Allowed%
- Size% = Allowed%
- Size% < 0
- Size%=0
- "Impulse_TransmitData", G_Impulse_TxPtr%, Size%, 0, 0, 0, 0, TASK_ID%
- G_Impulse_TxPtr% += Size%
- shell_ImpulseInTransmission = G_Impulse_TxInProgress%
- Impulse_Decode(
- Reason%,
- MethodToken%,
- Params%,
- Size% )
- Before%
- Before% = Reason%
- "Impulse_Decode", Reason%, q%, , , , IMPULSE_METHOD_TABLE, TASK_ID%
- Reason%, q%, , , , MethodToken%, Params%, Size%
- (Reason% = 0)
- (Before% <> 0)
- Reason% = Before%
- Impulse_GetString( Base%, Param%,
- Result$ )
- Base% = Base%!(Param% * 4)
- Base% = 0
- Result$ = ""
- ?Base% >= 32
- Result$ +=
- ?Base%
- Base% += 1
- Impulse_GetValue( Base%, Param%,
- Result% )
- Base% = Base%!(Param% * 4)
- Base% = 0
- # =
- ?Base% = 0
- Result% = Base%!1
- ( =
- Result% = 0
- + =
- Impulse_GetSwitch( Base%, Param% )
- = Base%!(Param% * 4) <> 0
- Impulse_NextTxTag
- G_Impulse_TxTag% += 1
- = G_Impulse_TxTag%
- Impulse_CurrentTxTag
- = G_Impulse_TxTag%
-